package com.itheima.backstage.controller;

import com.itheima.backstage.manager.SoulSubjectManager;
import com.itheima.vo.QuestionnaireVo;
import com.itheima.vo.SoulQuestionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
public class SoulSubjectController {
    @Autowired
    private SoulSubjectManager soulSubjectManager;

    //查询灵魂题目列表
    @GetMapping("/testSoul/findTestSoul")
    public List<QuestionnaireVo> findTestSoulList() {
        return soulSubjectManager.findTestSoulList();
    }

    //添加或修改试卷
    @PostMapping("/testSoul/saveTestSoul")
    public void saveTestSoul(@RequestBody QuestionnaireVo questionnaireVo) {
        soulSubjectManager.saveTestSoul(questionnaireVo);
    }

    //根据问卷id查询问卷信息
    @GetMapping("/testSoul/findTestSoul/{id}")
    public QuestionnaireVo findTestSoulById(@PathVariable("id") Long id) {
        return soulSubjectManager.findTestSoulById(id);
    }

    //根据问卷id查询问题和选项
    @GetMapping("/testSoul/findSoulQuestionVo/{id}")
    public List<SoulQuestionVo> findSoulQuestionVoList(@PathVariable("id") Long id) {
        return soulSubjectManager.findSoulQuestionVoList(id);
    }

    //文件上传
    @PostMapping("/uploadReportInfo")
    public String upload(MultipartFile uploadFile) throws IOException {
        return soulSubjectManager.upload(uploadFile);
    }

    //保存题目
    @PostMapping("/testSoul/saveQuestion")
    public void saveTestSoul(@RequestBody Map map) {
        soulSubjectManager.saveTestSoulQuestion(map);
    }

    //保存问题
    @PostMapping("/testSoul/saveQuestionOption")
    public void saveQuestionOption(@RequestBody Map map) {
        soulSubjectManager.saveTestSoulQuestionOption(map);
    }

    //保存问卷
    @PostMapping("/testSoul/saveQuestionnaire")
    public void saveQuestionnaire(@RequestBody Map map) {
        soulSubjectManager.saveQuestionnaire(map);
    }

    //根据问题id删除问题
    @GetMapping("/testSoul/deleteByQuestionId/{questionId}")
    public void deleteByQuestionId(@PathVariable Long questionId) {
        soulSubjectManager.deleteByQuestionId(questionId);
    }

    //根据问卷id删除问卷
    @GetMapping("/testSoul/deleteByQuestionnaireId/{questionnaireId}")
    public void deleteByQuestionnaireId(@PathVariable Long questionnaireId) {
        soulSubjectManager.deleteByQuestionnaireId(questionnaireId);
    }
}
